import axios from 'axios'

// 创建 axios 实例
const apiClient = axios.create({
  baseURL: 'http://localhost:5175',
  timeout: 10000,
})

// 请求拦截器
apiClient.interceptors.request.use(
  (config) => {
    // 可以在这里添加认证 token
    // const token = localStorage.getItem('token')
    // if (token) {
    //   config.headers.Authorization = `Bearer ${token}`
    // }
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)

// 响应拦截器
apiClient.interceptors.response.use(
  (response) => {
    return response
  },
  (error) => {
    console.error('API 请求错误:', error)
    return Promise.reject(error)
  }
)

// 工作流相关API
export const workflowAPI = {
  // 获取工作流列表
  getWorkflowList: async (params: {
    pageIndex: number
    pageSize: number
    doctorId?: number
    status?: string
  }) => {
    return await apiClient.get('/api/WorkflowGetWorkflowList', { params })
  },

  // 根据ID获取工作流详情
  getWorkflowById: async (id: number) => {
    return await apiClient.get(`/api/WorkflowGetWorkflowById?id=${id}`)
  },

  // 创建工作流
  createWorkflow: async (data: {
    doctorId: number
    serviceTypeIds: number[]
  }) => {
    return await apiClient.post('/api/WorkflowCreateWorkflow', data)
  },

  // 更新工作流步骤
  updateWorkflowStep: async (data: {
    stepId: number
    auditStatus: string
    remarks?: string
    auditor?: string
  }) => {
    return await apiClient.put('/api/WorkflowUpdateWorkflowStep', data)
  },

  // 获取服务类型列表
  getServiceTypes: async () => {
    return await apiClient.get('/api/WorkflowGetServiceTypes')
  }
}

export { apiClient } 